package com.taxi.driver.common;

import android.support.v4.app.Fragment;

import com.taxi.driver.module.main.duty.DutyFragment;
import com.taxi.driver.module.main.home.HomeFragment;
import com.taxi.driver.module.order.list.OrderListFragment;

/**
 * 功能描述："根据不同类型，控制页面跳转和fragment显示"的管理者
 */
public class AppController {

    private final static String CARPOOL_HOME = "com.taxi.driver.carpool.home.HomeFragment";
    private final static String CAPOOL_HOME_BTN = "com.taxi.driver.carpool.home.HomeBtnFragment";
    private final static String CAPOOL_ORDER_LIST = "com.taxi.driver.carpool.order.OrderListFragment_Carpool";

    /**
     * 获取首页fragment
     *
     * @return
     */
    public static Fragment getHomeFragment() {
        if (AppConfig.isCarpool()) {
            return getFragment(CARPOOL_HOME);
        }
        return HomeFragment.newInstance();
    }

    /**
     * 获取首页按键层
     *
     * @return
     */
    public static Fragment getHomeBtnFragment() {
        if (AppConfig.isCarpool()) {
            return getFragment(CAPOOL_HOME_BTN);
        }
        return DutyFragment.newInstance();
    }

    /**
     * 获取订单列表fragment
     *
     * @return
     */
    public static Fragment getOrderListFragment() {
        if (AppConfig.isCarpool()) {
            return getFragment(CAPOOL_ORDER_LIST);
        }
        return OrderListFragment.newInstance();
    }

    private static Fragment getFragment(String className) {
        try {
            Class<Fragment> clz = (Class<Fragment>) Class.forName(className);
            return clz.newInstance();
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
            e.printStackTrace();
        }
        return null;
    }

}
